package pCloud.acesscontrol;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import pCloud.PCloudAttributeAndType;

import com.sun.xacml.Target;
import com.sun.xacml.TargetMatch;
import com.sun.xacml.attr.AttributeDesignator;
import com.sun.xacml.attr.IntegerAttribute;
import com.sun.xacml.attr.StringAttribute;

/**
 * @author ttadinh
 * Matching resource, which is the stream ID
 */
public class SubjectMatchIntegerLE extends Match{
	int key;
	public SubjectMatchIntegerLE(int k){
		this.key = k;
	}
	
	@Override
	public List getMatchTarget() throws Exception {
		List subjects = new ArrayList();
		List subject = new ArrayList();

		URI resourceDesignatorType = new URI(PCloudAttributeAndType.TYPE_INTEGER);
		URI resourceDesignatorId = new URI(PCloudAttributeAndType.SUBJECT_KEY_ID);
		
		AttributeDesignator resourceDesignator = new AttributeDesignator(
				AttributeDesignator.SUBJECT_TARGET, resourceDesignatorType,
				resourceDesignatorId, false);
		
		IntegerAttribute resourceValue = new IntegerAttribute(this.key);
		
		subject.add(createTargetMatch(TargetMatch.SUBJECT, PCloudAttributeAndType.MATCH_INTEGER_LE,
				resourceDesignator, resourceValue));
		subjects.add(subject);
		return subjects;
	}	
	
}
